package com.smart.manager.work.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.smart.common.entities.ajax.AjaxResult;
import com.smart.common.entities.constant.ExceptionTips;
import com.smart.common.entities.constant.SmartConstant;
import com.smart.common.entities.core.Page;
import com.smart.manager.work.entities.body.RBasicStaff;
import com.smart.manager.work.entities.models.BasicStaff;
import com.smart.manager.work.repository.BasicStaffRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.List;


/**
 * 管家资料
 * @author leo
 * @date 2023/09/10
 */
@Api(tags =  "管家资料")
@RestController
@RequestMapping(SmartConstant.MANAGER_API_PREFIX + "work/basic/staff")
@RequiredArgsConstructor
public class BasicStaffApi {

    private final BasicStaffRepository repository;
    
    @GetMapping(value = "pageList")
    @ApiOperation(value = "查询管家")
    @SaCheckPermission("work:basic:staff:pageList")
    public AjaxResult<Page<BasicStaff>> pageList(@Validated RBasicStaff.SearchBody body) {
        Page<BasicStaff> result = repository.pageList(body);
        return AjaxResult.data(result);
    }

    @ApiOperation(value = "添加管家")
    @PostMapping("add")
    @SaCheckPermission("work:basic:staff:add")
    public AjaxResult<String> add(@RequestBody @Validated RBasicStaff.EditBody data) {
        repository.add( data );
        return AjaxResult.success();
    }


    @ApiOperation(value = "修改管家")
    @PutMapping("update/{id}")
    @SaCheckPermission("work:basic:staff:update")
    public AjaxResult<String> update(@PathVariable Long id, @RequestBody @Validated RBasicStaff.EditBody data) {
        repository.update( id, data );
        return AjaxResult.success();
    }


    @ApiOperation(value = "删除管家")
    @DeleteMapping("delete")
    @SaCheckPermission("work:basic:staff:delete")
    public AjaxResult<Integer> delete(@RequestBody @NotEmpty(message = ExceptionTips.PK_EMPTY) List<Long> ids) {
        int i = repository.delByIds( ids );
        return AjaxResult.delSuccess( i );
    }

}
